package com.zerdoor.controller;

import com.zerdoor.model.UserInfo;
import com.zerdoor.pagehelper.PageHelper;
import com.zerdoor.pagehelper.PageInfo;
import com.zerdoor.service.MemOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by xiaoji on 2015/1/6.
 */
@Controller
@RequestMapping("/memorder")
public class MemOrderController {

    @Autowired
    private MemOrderService memOrderService;
    /**
     * 会员商品订单页
     * @return
     */
    @RequestMapping("/toProOrder")
    public String toProOrder(){
        return "/usercenter/proOrder";
    }

    /**
     * 查询会员商品订单
     * @param request
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping(value = "/getProOrder", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getProOrder(HttpServletRequest request,int page,int rows){
        UserInfo userInfo = (UserInfo)request.getSession().getAttribute("curUser");
        Map<String,Object> map = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);
        List<Map<String, Object>> list = memOrderService.getProOrderList(userInfo.getArtistId());
        //读取会员作品订单信息
        PageInfo pageInfo = new PageInfo(list);
        map.put("pageInfo",pageInfo);
        return map;
    }
}
